#ifndef CONNECTION_H
#define CONNECTION_H

#include <string>

struct sqlite3;
struct sqlite3_stmt;

namespace Tvimeg
{
	class File;

	class Connection
	{
	public:
		Connection(const File& databaseFile);
		~Connection(void);

		bool			ExecuteQuery(const std::string& query);
		bool			ExecuteQuery(void);

		bool			PrepareQuery(const std::string& query);
		bool			NextRow(void);
		void			FinalizeQuery(void);

		void			BindText(const int parameter, const std::string& text);
		void			BindInt(const int parameter, const int value);
		void			BindFloat(const int parameter, const float value);

		int				GetColumnCount(void) const;

		std::string		GetString(const int column) const;
		int				GetInt(const int column) const;

		std::string		GetString(const std::string& query, const int column);
		int				GetInt(const std::string& query, const int column);

		int				GetLastId(void) const;

	private:
		void			CloseDatabase(void);

		void			PrintError(const std::string& error) const;

		sqlite3*		database;
		sqlite3_stmt*	currentQuery;

		bool			hasRow;
	};
}

#endif // CONNECTION_H
